<?php
/*
 * @Author: CYH
 * @Date: 2020-10-31 10:25:06
 * @LastEditTime: 2021-03-23 09:02:12
 * @LastEditors: Please set LastEditors
 * @Description: 资产管理control类
 * @FilePath: \application\controllers\Article\Article.php
 */
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');
// 响应类型  
header('Access-Control-Allow-Methods:POST');
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type:application/json,charset:utf-8');

// 资产管理control类
class Article extends CI_Controller
{
    // 构造方法
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Article/Article_manage');
        $this->load->helper('url_helper');
        $this->load->library('session');
        // $this->load->helper('date');
        $this->load->helper(array('form', 'url', 'date'));
    }

    /**
     * @description: 房间资产初始化登陆方法
     * @param {initPassword}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function room_article_init_login()
    {

        $password_router = $_POST['password_router'];//管理员密码

        // $initPassword = "123456";

        $result_json = $this->Article_manage->room_article_init_login($initPassword);

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间资产初始化表单方法
     * @param {area_number, floor_number, floor1, floor2}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function room_article_init_form()
    {

        $area_number = $_POST['area_number'];   //区域编号
        $floor_number = $_POST['floor_number']; //宿舍楼编号
        $floor1 = $_POST['floor1'];             //宿舍楼层号上限
        $floor2 = $_POST['floor2'];             //宿舍楼层号下限

        // $area_number = "1585";
        // $floor_number = "1";
        // $floor1 = "1";
        // $floor2 = "1";

        $result_json = $this->Article_manage->room_article_init_form(
            $area_number,
            $floor_number,
            $floor1,
            $floor2
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间初始化新增资产方法
     * @param {area_number, floor_number, floor1, floor2, dorm_property_description, dorm_property_number, totalNumber, price, compensation_price}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function room_article_init_add()
    {

        $area_number = $_POST['area_number'];                            //区域编号
        $floor_number = $_POST['floor_number'];                          //宿舍楼编号
        $floor1 = $_POST['floor1'];                                      //宿舍楼层上限
        $floor2 = $_POST['floor2'];                                      //宿舍楼层下限
        $dorm_property_description = $_POST['dorm_property_description'];//宿舍固定资产描述
        $dorm_property_number = $_POST['dorm_property_number'];          //宿舍固定资产编码
        $totalNumber = $_POST['totalNumber'];                            //总数量
        $price = $_POST['price'];                                        //物品单价
        $compensation_price = $_POST['compensation_price'];              //赔偿单价

        // $area_number = "1585";
        // $floor_number = "1";
        // $floor1 = "3";
        // $floor2 = "4";
        // $dorm_property_description = "被子";
        // $dorm_property_number = "1";
        // $totalNumber = "1";
        // $price = "1";
        // $compensation_price = "1";

        $result_json = $this->Article_manage->room_article_init_add(
            $area_number ,
            $floor_number,
            $floor1,
            $floor2,
            $dorm_property_description,
            $dorm_property_number,
            $totalNumber,
            $price,
            $compensation_price
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 领用物品新增方法
     * @param {area_number, floor_number, article_name, article_number, price,compensation_price, totalNumber, remarks}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function receiving_items_add()
    {

        $area_number = $_POST['area_number'];                           //区域编号 
        $floor_number = $_POST['floor_number'];                         //宿舍楼编号
        $article_name = $_POST['article_name'];                         //领用物品描述
        $article_number = $_POST['article_number'];                     //领用物品编号
        $price = $_POST['price'];                                       //物品单价
        $compensation_price = $_POST['compensation_price'];             //赔偿价格
        $totalNumber = $_POST['totalNumber'];                           //总数量
        $remarks = $_POST['remarks'];                                   //备注

        // $area_number = "1585";
        // $floor_number = "1";
        // $article_name = "1";
        // $article_number = "1"; 
        // $price =  "1";
        // $compensation_price = "1";
        // $totalNumber = "1";
        // $remarks = "备注";

        $result_json = $this->Article_manage->receiving_items_add(
            $area_number,
            $floor_number,
            $article_name,
            $article_number,
            $price,
            $compensation_price,
            $totalNumber,
            $remarks
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description:领用物品停用方法 
     * @param {area_number, floor_number, article_number}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function receiving_items_delete()
    {

        $area_number = $_POST['area_number'];        //区域编号
        $floor_number= $_POST['floor_number'];       //宿舍楼编号
        $article_number = $_POST['article_number'];  //物品编号

        // $area_number = "1585";
        // $floor_number = "1";
        // $article_number = "B04";

        $result_json = $this->Article_manage->receiving_items_delete(
            $area_number,
            $floor_number,
            $article_number
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 领用物品修改方法
     * @param {area_number, floor_number, article_number, article_name, price, compensation_price, totalNumber, remarks}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function receiving_items_update()
    {

        $area_number = $_POST['area_number'];               //区域编号
        $floor_number = $_POST['floor_number'];             //宿舍楼编号
        $article_number = $_POST['article_number'];         //物品编号
        $article_name = $_POST['article_name'];             //物品名称
        $price = $_POST['price'];                           //物品单价
        $compensation_price = $_POST['compensation_price']; //赔偿价格
        $totalNumber = $_POST['totalNumber'];               //总数量
        $remarks = $_POST['remarks'];                       //备注

        // $area_number = "1585";
        // $floor_number = "1";
        // $article_number = "B02";
        // $article_name = "床";
        // $price = "1";
        // $compensation_price = "1";
        // $totalNumber = "10";
        // $remarks = "备注";

        $result_json = $this->Article_manage->receiving_items_update(
            $area_number,
            $floor_number,
            $article_number,
            $article_name,
            $price,
            $compensation_price,
            $totalNumber,
            $remarks
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 领用物品查询方法
     * @param {area_number, floor_number, article_number, article_name, limit}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function receiving_items_select()
    {

        $area_number = $_POST['area_number'];       //区域编号
        $floor_number = $_POST['floor_number'];     //宿舍楼编号
        $article_number = $_POST['article_number']; //物品编号
        $article_name = $_POST['article_name'];     //物品描述
        $limit = $_POST['limit'];                   //页数

        // $area_number = "";
        // $floor_number = "";
        // $article_number = "";
        // $article_name = "";
        // $limit = "1";

        $result_json = $this->Article_manage->receiving_items_select(
            $area_number,
            $floor_number,
            $article_number,
            $article_name,
            $limit
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品新增方法_搜索方法：查询区域下是否有宿舍楼
     * @param {area_number}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_add_ssl_number()
    {

        $area_number = $_POST['area_number'];//区域编号

        // $area_number = "1585";

        $result_json = $this->Article_manage->fixedassets_add_ssl_number($area_number);

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品新增方法_搜索方法：查询宿舍楼下楼层
     * @param {area_number, floor_number}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_add_ssl_floor()
    {

        $area_number = $_POST['area_number'];   //区域编号
        $floor_number = $_POST['floor_number']; //宿舍楼编号

        // $area_number = "1585"; 
        // $floor_number = "1";

        $result_json = $this->Article_manage->fixedassets_add_ssl_floor(
            $area_number,
            $floor_number
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品新增方法_搜索方法：查询宿舍楼楼层房间
     * @param {area_number, floor_number, dorm_floor}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_add_ss_number()
    {

        $area_number = $_POST['area_number'];   //区域编号
        $floor_number = $_POST['floor_number']; //宿舍楼编号
        $dorm_floor = $_POST['dorm_floor'];     //宿舍楼层号

        // $area_number = "1585";
        // $floor_number = "1";
        // $dorm_floor = "3";

        $result_json = $this->Article_manage->fixedassets_add_ss_number(
            $area_number,
            $floor_number,
            $dorm_floor
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品新增方法
     * @param {area_number, floor_number, dorm_floor, room_number, dorm_property_description, dorm_property_number, price, compensation_price, totalNumber}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_add()
    {

        $area_number = $_POST['area_number'];                               //区域编号
        $floor_number = $_POST['floor_number'];                             //宿舍楼编号
        $dorm_floor = $_POST['dorm_floor'];                                 //宿舍楼层号
        $room_number = $_POST['room_number'];                               //宿舍房间号
        $dorm_property_description = $_POST['dorm_property_description'];   //宿舍固定资产描述
        $dorm_property_number = $_POST['dorm_property_number'];             //宿舍固定资产编码
        $price = $_POST['price'];                                           //物品单价
        $compensation_price = $_POST['compensation_price'];                 //赔偿价格
        $totalNumber = $_POST['totalNumber'];                               //总数量

        // $area_number = "1585";
        // $floor_number = "1";
        // $dorm_floor = "3";
        // $room_number = "301";
        // $dorm_property_description  = "空调";
        // $dorm_property_number = "2";
        // $price = "100";
        // $compensation_price = "100";
        // $totalNumber = "1";

        $result_json = $this->Article_manage->fixedassets_add(
            $area_number,
            $floor_number,
            $dorm_floor,
            $room_number,
            $dorm_property_description,
            $dorm_property_number,
            $price,
            $compensation_price,
            $totalNumber
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品删除方法
     * @param {area_number, floor_number, dorm_floor, room_number, dorm_property_number}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_delete()
    {

        $area_number = $_POST['area_number'];                   //区域编号
        $floor_number = $_POST['floor_number'];                 //宿舍楼编号
        $dorm_floor = $_POST['dorm_floor'];                     //宿舍楼层号
        $room_number = $_POST['room_number'];                   //宿舍房间号
        $dorm_property_number = $_POST['dorm_property_number']; //宿舍固定资产编码

        // $area_number = '1585';
        // $floor_number = '1';
        // $dorm_floor =   '3';
        // $room_number = '301';
        // $dorm_property_number = '1';

        $result_json = $this->Article_manage->fixedassets_delete(
            $area_number,
            $floor_number,
            $dorm_floor,
            $room_number,
            $dorm_property_number
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品修改方法
     * @param {area_number, floor_number, room_number, dorm_property_number, dorm_property_description, price,compensation_price, dorm_property_remarks}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_update()
    {

        $area_number = $_POST['area_number'];                               //区域编号
        $floor_number = $_POST['floor_number'];                             //宿舍楼编号
        $room_number = $_POST['room_number'];                               //宿舍房间号
        $dorm_property_number = $_POST['dorm_property_number'];             //物品编号
        $dorm_property_description = $_POST['dorm_property_description'];   //物品描述
        $price  = $_POST['price'];                                          //物品单价      
        $compensation_price = $_POST['compensation_price'];                 //赔偿价格
        $dorm_property_remarks = $_POST['dorm_property_remarks'];           //备注

        // $area_number = "1585";
        // $floor_number = "1";
        // $room_number = "301";
        // $dorm_property_number = "2";
        // $dorm_property_description = "空调";
        // $price  = "100";
        // $compensation_price = "100";
        // $dorm_property_remarks = "备注";

        $result_json = $this->Article_manage->fixedassets_update(
            $area_number,
            $floor_number,
            $room_number,
            $dorm_property_number,
            $dorm_property_description,
            $price,
            $compensation_price,
            $dorm_property_remarks
        );

        echo $result_json;

        return 0;
    }

    /**
     * @description: 房间物品查詢方法
     * @param {area_number, floor_number, dorm_floor, room_number, limit}
     * @return json:array{'res'=>'','msg'=>'','data'=>''}
     */    
    public function fixedassets_select()
    {

        $area_number = $_POST['area_number'];   //区域编号
        $floor_number = $_POST['floor_number']; //宿舍楼编号
        $dorm_floor = $_POST['dorm_floor'];     //宿舍楼层号
        $room_number = $_POST['room_number'];   //宿舍房间号
        $limit = $_POST['limit'];               //页数

        // $area_number = "";
        // $floor_number = "";
        // $dorm_floor = "";
        // $room_number = "";
        // $limit = "1";

        $result_json = $this->Article_manage->fixedassets_select(
            $area_number,
            $floor_number,
            $dorm_floor,
            $room_number,
            $limit
        );

        echo $result_json;

        return 0;
    }
}
